#include <vector>
#include <fstream>

using namespace std;

int pourMilk(int x, int y, int m) {
  int answer = 0;
  for (int i = 0; i <= 1000; ++i) {
    // 只用 x 桶的情况
    if (x * i > m) {
      // 只用 x 桶就溢出了
      break;
    }
    for (int j = 0; j <= 1000; ++j) {
      int total = x * i + y * j;
      if (total > m) {
        // 溢出
        break;
      }

      answer = max(answer, total);
    }
  }

  return answer;
}

int main(int argc, char const *argv[])
{
  /* code */
  ifstream ifs("PourMilk.in");
  int x = 0, y = 0, m = 0;
  ifs >> x >> y >> m;

  ofstream ofs("PourMilk.out");
  ofs << pourMilk(x, y, m);

  return 0;
}


